package org.example.backend.controller;

import org.example.backend.domain.SysMenu;
import org.example.backend.domain.SysUser;
import org.example.backend.service.impl.SysMenuServiceImpl;
import org.example.backend.service.impl.SysUserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;
import java.util.List;



@RestController
@RequestMapping("/api")
public class UserLoginController {
    @Autowired
    private SysUserServiceImpl sysUserServiceImpl;

    @Autowired
    private SysMenuServiceImpl sysMenuServiceImpl;

    @GetMapping("/talent/list")
    public DataResult getUserList() {
        List<SysUser> list = sysUserServiceImpl.list();
        return DataResult.success(list);
    }

    @PostMapping("/user/insert")
    public DataResult insertUser(@RequestBody SysUser user) {
        sysUserServiceImpl.insertUser(user);
        return DataResult.success();
    }

    @GetMapping("/user/logout")
    public DataResult logout(){
        SecurityContextHolder.clearContext();
        return DataResult.success("退出成功");
    }

    @GetMapping("/menu/list")
    public DataResult findMenuTree(){
        List<SysMenu> menuTree = sysMenuServiceImpl.findMenuTree();
        return DataResult.success(menuTree);
    }
}
